<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数调用-用户名检测</title>
</head>

<body>
    <form name="form1" action="#" method="POST">
        请输入姓名：<input type="text" name="userName" id="userName" size="30">
        <input type="button" value="检测" onclick="checkName()" />
        <select name="sel" id="sel" onchange="change()">
            <option>请选择</option>
            <option>香蕉</option>
            <option>苹果</option>
        </select>
        <br>
        <input type="text" name="" id="" onselect="select1()">
        <input type="button" name="save" id="save" value="保存">
    </form>
    <script>
        var bt_save = document.getElementById("save");
        bt_save.onclick = function() {
            alert("点击了保存按钮")
        }
    </script>
    <script>
        function checkName() {
            var str = form1.userName.value;
            if (str.trim() == "") {
                alert("姓名不能为空！");
            } else {
                alert("您输入的是：" + str);
            }
        }

        function select1() {
            alert("选中了文本")
        }

        function change() {
            var s = form1.sel.value;
            if (s == '请选择') {
                return;
            }
            alert(s)
        }
    </script>
</body>

</html>